package client;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import message.Order;

public class LoadTestSimple {

	static int LIVE_ORDERS_NUMER = 1_000_000;

	public static void main(String[] args) throws UnknownHostException,
			IOException {

		Socket requestSocket;
		requestSocket = new Socket("localhost", 2013);
		new Thread(new SocketReader(requestSocket)).start();
		SocketWriter sw = new SocketWriter(requestSocket, "client2");
		sw.initForLoadTest();
		sw.sendLogin("client2");

		int cycle = 0;
		
		long time = System.currentTimeMillis();
//while (true){
	cycle++;
		for (int i = 0; i < LIVE_ORDERS_NUMER; i++) {
			sw.sendOrder(new Order("client1", "orderSell"+cycle+"_"+i, "IBM", 2, (double) i, 30));
		//	sw.sendOrder(new Order("client1", "orderBuy"+cycle+"_"+i, "IBM", 1, (double) i, 30));
			
		}
		System.out.println("init load time="+(System.currentTimeMillis()-time));
		//sleep(10000);
}
//	}

	
	
	static void sleep(int milisec) {
		try {
			Thread.sleep(milisec);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
	}

}
